<?php
namespace app\admin\controller\Speech;
use support\exception\ValidateException;
use app\admin\model\Speech\Aly as AlyModel;
use app\admin\controller\CommonController;
use think\facade\Db;

class AlyController extends CommonController{



	/**
	 *@description 阿里云
	 *@buildcode(true)
	*/
	public function index(){
		if($this->request->method() == 'GET'){
			return view('speech/aly/index');
		}else{
			$data = $this->request->post();
			$validate = new \app\admin\validate\Speech\AlyValidate;
			if(!$validate->scene('index')->check($data)){
				throw new ValidateException ($validate->getError());
			}

			$info = AlyModel::column('data','name');
			foreach ($data as $key => $value) {
				if(array_key_exists($key,$info)){
					AlyModel::field('data')->where(['name'=>$key])->update(['data'=>$value]);
				}else{
					AlyModel::create(['name'=>$key,'data'=>$value]);
				}
			}
			return json(['status'=>200,'msg'=>'操作成功']);
		}
	}


	/**
	 *@description 修改信息之前查询信息的
	 *@buildcode(true)
	*/
	function getInfo(){
		$res = AlyModel::column('data','name');

		$data['status'] = 200;
		$data['data'] = $res;
		return json($data);
	}


}